<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>添加门店页</title> 
    
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
 
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="/public/static/admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/public/static/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/public/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/public/static/admin/css/animate.css" rel="stylesheet">
    <link href="/public/static/admin/css/style.css?v=4.0.0" rel="stylesheet">
    <link href="/public/static/admin/css/ourstyle.css?v=4.0.0" rel="stylesheet">
</head>

<body class="fixed-sidebar full-height-layout gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>门店内容</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                            <form action="" method="post" id="adsConFrom" onclick="return false;" class="form-horizontal">
                                <input type="hidden" name="city_id" id="category_pid" value="{$one.city_id}">
                                <input type="hidden" name="count" id="category_count" value="">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">城市分类</label>
                                    <div class="col-sm-2">
                                    <select class="form-control category_add" count="0" >
                                        <option value="0">请选择</option>
                                        {foreach name="city" item="v"}
                                        <option value="{$v.id}" {if $v['id'] eq $sheng_now['id']}selected=selected{/if}>{$v.name}</option>
                                        {/foreach}
                                    </select>
                                    </div>
                                    <if condition="$shi_now">
                                       <div class="col-sm-2">
                                        <select class="form-control category_add" count="1" >
                                            <option value="0">请选择</option>
                                            {foreach name="shi" item="v"}
                                            <option value="{$v.id}" {if $v['id'] eq $shi_now['id']}selected=selected{/if}>{$v.name}</option>
                                            {/foreach}
                                        </select>
                                        </div> 
                                    </if>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">门店标题：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="title" minlength="2" type="text" value="{$one.title}" required="" aria-required="true" placeholder="填写门店标题">
                                    </div>
                                </div> 
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">门店地址：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="address" minlength="2" type="text" value="{$one.address}" required="" aria-required="true" placeholder="填写门店地址">
                                    </div>
                                </div> 
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">转换坐标地址：</label>
                                    <div class="col-sm-6">
                                        <input class="configInput form-control" name="add_site" value="{$one.add_site}" id="add_site" minlength="2" type="text" value="" required="" aria-required="true" placeholder="填写有效地址">
                                    </div>
                                    <button class="btn btn-primary" onclick="make_site()">生成坐标</button>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">横坐标：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="map_x" id="map_x" minlength="2" type="text" value="{$one.map_x}" placeholder="填写地图横坐标">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">纵坐标：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="map_y" id="map_y" minlength="2" type="text" value="{$one.map_y}" placeholder="填写地图纵坐标">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">咨询热线：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="tel" minlength="2" type="text" value="{$one.tel}" required="" aria-required="true" placeholder="填写咨询热线">
                                    </div>
                                </div> 
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">营业时间：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="shop_time" minlength="2" type="text" value="{$one.shop_time}" required="" aria-required="true" placeholder="填写营业时间">
                                    </div>
                                </div> 

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">产品多图：</label>
                                    <div class="col-sm-8">
                                        <table class="table table-hover">
                                            <thead>
                                                <tr>
                                                    <th style="width:30%">图片</th>
                                                    <!-- <th>链接地址（必填）</th> -->
                                                    <th>图片标题</th>
                                                    <th style="width:80px">操作</th>
                                                </tr>
                                            </thead>
                                            <tbody id="SildeImgs">
                                                <tr>
                                                    <td><div class="input-group"><input type="text" class="form-control upload-path" id="slide_img_0" name="slide_img[]" value="" placeholder="请输入图片地址"><span class="input-group-btn"><button type="button" class="btn btn-primary" onclick="BrowseServer('slide_img_0')"><i class="fa fa-search"></i></button></span></div></td>
                                                    <!-- <td><input type="text" class="form-control" id="slide_link_0" name="slide_link[]" value="" placeholder="请输入链接地址"></td> -->
                                                    <td><input type="text" class="form-control" id="slide_alt_0" name="slide_alt[]" value="" placeholder="请输入图片标题"></td>
                                                    <td><button type="button" class="btn btn-sm btn-success" onClick="addSlideRow();"><i class="fa fa-plus-square"></i> 添加</button></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">序号：</label>
                                    <div class="col-sm-8">
                                        <input class="configInput form-control" name="sort" type="text" class="configInput" value="50">
                                    </div>
                                </div>

                                <div class="hr-line-dashed"></div>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-2">
                                        <input type="hidden" name="id" value="{$one.id}" >
                                        <button class="btn btn-primary" onclick="ajax_submit_form('adsConFrom','{:url('Shop/shop_edit')}')" type="submit">保存</button>
                                    </div>
                                </div> 
                    	    </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

    <!-- 全局js -->
    <!-- <script src="/public/static/admin/js/jquery.min.js?v=2.1.4"></script> -->
    <script src="/public/static/admin/js/jQuery-2.1.4.min.js"></script>
    <script src="/public/static/admin/js/bootstrap.min.js?v=3.3.5"></script>
	<!-- 自定义js -->
    <script src="/public/static/admin/js/content.js?v=1.0.0"></script>
    <script src="/public/static/admin/js/plugins/layer/layer.min.js"></script>
    <script src="/public/static/admin/plugins/laydate/laydate.js"></script>
    <script src="/public/static/admin/js/article.js"></script> 
    <!-- CKeditor -->
    <script src="/public/static/admin/plugins/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="/public/static/admin/plugins/ckfinder/ckfinder.js"></script> 
    <!-- iCheck -->
    <script src="/public/static/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script>
        var index = parent.layer.getFrameIndex(window.name);
        function closethisdialog() {
            parent.layer.close(index);
        }
        function ChangeType() {
            var styles, key, val;
            val = $('#AdsType').val();
            styles = new Array('0', '1', '2', '3', '4');
            for (key in styles) {
                if (styles[key] == val) {
                    $("#adstype_" + styles[key]).removeClass('hide');
                } else {
                    $("#adstype_" + styles[key]).addClass('hide');
                }
            }
        }
        var htmlText = '<tr id="slideTR_{0}">';
        htmlText += '<td><div class="input-group"><input type="text" class="form-control upload-path" id="slide_img_{0}" name="slide_img[]" value="" placeholder="请输入图片地址"><span class="input-group-btn"><button type="button" class="btn btn-primary" onclick="BrowseServer(\'slide_img_{0}\')"><i class="fa fa-search"></i></button></span></div></td>';
        // htmlText += '<td><input type="text" class="form-control" id="slide_link_{0}" name="slide_link[]" value="" placeholder="请输入链接地址"></td>';
        htmlText += '<td><input type="text" class="form-control" id="slide_alt_{0}" name="slide_alt[]" value="" placeholder="请输入图片标题"></td>';
        htmlText += '<td><button type="button" class="btn btn-sm btn-danger" onclick="delmySlideRow({0})"><i class="fa fa-minus-square"></i> 删除</button></td></tr>';
        var items = 1;

        function addSlideRow() {
            var lastitem = items - 1;
            var newHtmlTr = htmlText.replace(/\{0\}/g, items);
            $('#SildeImgs').append(newHtmlTr);
            items += 1;
        }
        function delmySlideRow(id) {
            $("#slideTR_" + id).remove();
        } 

        $(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
            // DoPost("addAdsForm"); 
        }) 

        var jsonstr2 = '<?php echo $one['content'] ?>';
        $(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
            // DoPost("addAdsForm");
            FillAds(''+jsonstr2+'');
            //JS加载广告内容
            function FillAds(content) {
                // var json = eval(content);
                var json = eval("("+content+")");
                // alert(content);
                for(i=0;i<json.length;i++)
                {
                    if(i ==0)
                    {
                        // $("#slide_width").val(json[0].width);
                        // $("#slide_height").val(json[0].height);
                    }
                    else
                    {
                        addSlideRow();//增加一行
                    }
                    $("#slide_img_"+i).val(json[i].image);
                    $("#slide_alt_"+i).val(json[i].alt);
                }
            }
        })
        

$(function(){
    $(document).on('change','.category_add',function(){
        var ht = $(this);
        var val = ht.val();
        var count = parseInt(ht.attr('count'));
        // alert(count);//count>0二级以下不再查询
        if(val==0){
            return false;
        }
        $('#category_pid').val(val);
        $('#category_count').val(count+1);
        ht.parent().nextAll().remove();
        //count>0二级以下不再查询
        if(count>0){
            return false;
        }
        // alert(val);
        // return false;
        $.ajax({ 
            url:"{:url('Shop/get_son')}",
            // data:'acc=123',
            data:{val:val},
            type:'get',
            dataType:'json',
            success:function(result){
                // alert(result);
                var id = $('#category_id').val();//隐藏框的分类id
                if(result.category){
                    var res = result.category;
                    count++;
                    var select = '<div class="col-sm-2"><select class="form-control category_add" count="'+count+'"><option value="0">请选择</option>';
                    for(var i = 0 in res){
                        if(res[i].id != id){
                            select += '<option value="'+res[i].id+'">'+res[i].name+'</option>';
                        }else{
                            var pig = 1;
                        }
                    }    
                    if(pig == 1 && !res[1]){
                        return false;
                    }
                    select += '</select></div>';
                    ht.parent().parent().append(select);
                    // $('select').select2();
                }
                
            }
        });
        return false;
    });
});

</script>
<script>
function make_site(){
    var add_site = $("#add_site").val();
    if(add_site == ''){
        layer.msg("请输入地址");
        return false;
    }
    var url = 'http://api.map.baidu.com/geocoder/v2/?ak=eIxDStjzbtH0WtU50gqdXYCz&output=json&address=' + encodeURIComponent(add_site);
      //根据地点名称获取经纬度信息
      $.ajax({
          type: "POST",
          url: url,
          dataType: "JSONP",
          success: function (data){
                // console.log(data.result.location);
              if (parseInt(data.status) == 0) {
                  $("#map_x").val(data.result.location.lng);
                  $("#map_y").val(data.result.location.lat);
              }else{
                layer.msg("请输入有效地址");
              }
          }
      });
}
</script>
</body>
</html>
